package com.sgb.kjwl.view.widget.pick;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.GridLayoutManager;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.LayoutPickDetailSupplementBinding;
import com.sgb.kjwl.model.entity.pick.TenderAddenduEntity;
import com.sgb.kjwl.view.ui.activity.pick.PickTenderAddendumActivity;
import com.sgb.kjwl.view.ui.adapter.pick.PickDetailSupplementAdapter;
import com.sgb.kjwl.viewmodel.pick.TenderDetailsModel3;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.List;

/**
 * @Description:
 * @Author:         王娇
 * @UpdateUser:     张驰
 * @UpdateDate:     2020年09月24
 * @UpdateRemark:   报名详情页中投标补遗
 * @Version:        招采 2.9.1
 */
public class PickDetailSupplementView extends LinearLayout {
    private Context mContext;
    private LayoutPickDetailSupplementBinding binding;
    private PickDetailSupplementAdapter pickDetailSupplementAdapter;

    public PickDetailSupplementView(Context context) {
        super(context);
        this.mContext = context;
        initView();
    }

    public PickDetailSupplementView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        initView();
    }

    public PickDetailSupplementView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        initView();
    }

    private void initView() {
        binding = DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.layout_pick_detail_supplement, this, true);
    }

    public void showInfoView(List<TenderAddenduEntity> tenderAddenduEntityList, TenderDetailsModel3 viewModel, String tenderId, String titleName) {
        if (tenderAddenduEntityList == null) {
            binding.pickRecycler.setVisibility(View.GONE);
//            binding.emptyView.setVisibility(View.VISIBLE);
            return;
        }
        if (tenderAddenduEntityList.size() == 0) {
            binding.pickRecycler.setVisibility(View.GONE);
//            binding.emptyView.setVisibility(View.VISIBLE);
            return;
        }

        if (tenderAddenduEntityList.size() >= 20) {
            binding.tvMoreData.setVisibility(VISIBLE);
            binding.tvMoreData.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    PickTenderAddendumActivity.start(mContext,tenderId,titleName);
                }
            });
        }
        pickDetailSupplementAdapter = new PickDetailSupplementAdapter(mContext, tenderAddenduEntityList);
        GridLayoutManager rightManager = new GridLayoutManager(mContext, 1);
        binding.pickRecycler.setLayoutManager(rightManager);
        binding.pickRecycler.setAdapter(pickDetailSupplementAdapter);
        pickDetailSupplementAdapter.setOnItemClick(new AdapterOnItemClick<TenderAddenduEntity>() {
            @Override
            public void onItemClick(TenderAddenduEntity tenderAddenduEntity, int position) {
                viewModel.getStringUrl("addendumDetail",tenderAddenduEntity.getNo());
            }
        });
    }
}
